home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / util / dialtest.c++ < prev    next >
C/C++ Source or Header  |  1994-08-01  |  4KB  |  128 lines

  1. /*    $Header: /usr/people/sam/fax/util/RCS/dialtest.c++,v 1.10 1994/02/28 14:24:25 sam Rel $ */
  2. /*
  3.  * Copyright (c) 1990, 1991, 1992, 1993, 1994 Sam Leffler
  4.  * Copyright (c) 1991, 1992, 1993, 1994 Silicon Graphics, Inc.
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and 
  7.  * its documentation for any purpose is hereby granted without fee, provided
  8.  * that (i) the above copyright notices and this permission notice appear in
  9.  * all copies of the software and related documentation, and (ii) the names of
  10.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  11.  * publicity relating to the software without the specific, prior written
  12.  * permission of Sam Leffler and Silicon Graphics.
  13.  * 
  14.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  15.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  16.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  17.  * 
  18.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  19.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  20.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  22.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  23.  * OF THIS SOFTWARE.
  24.  */
  25. /*
  26.  * Program for interactively using dial string rules.
  27.  *
  28.  * Usage: dialtest [-v] [-a areacode] [-c countrycode]
  29.  *    [-i internationalprefix] [-l longdistanceprefix] dial-rules-file
  30.  */
  31. #include <stdlib.h>
  32. #include "DialRules.h"
  33.  
  34. extern    void fxFatal(const char* va_alist ...);
  35.  
  36. static    const char* appName;
  37.  
  38. static void
  39. usage()
  40. {
  41.     fxFatal("usage: %s"
  42.     " [-v]"
  43.     " [-a area-code]"
  44.     " [-c country-code]"
  45.     " [-i international-prefix]"
  46.     " [-l long-distance-prefix]"
  47.     " dialrules"
  48.     , appName
  49.     );
  50. }
  51.  
  52. static int
  53. prompt()
  54. {
  55.     printf("ready> "); fflush(stdout);
  56.     return (1);
  57. }
  58.  
  59. int
  60. main(int argc, char* argv[])
  61. {
  62.     char* areaCode = "415";
  63.     char* countryCode = "1";
  64.     char* internationalPrefix = "011";
  65.     char* longDistancePrefix = "1";
  66.     fxBool verbose = FALSE;
  67.     extern int optind, opterr;
  68.     extern char* optarg;
  69.     int c;
  70.  
  71.     appName = argv[0];
  72.     while ((c = getopt(argc, argv, "a:c:i:l:v")) != -1)
  73.     switch (c) {
  74.     case 'a':
  75.         areaCode = optarg;
  76.         break;
  77.     case 'c':
  78.         countryCode = optarg;
  79.         break;
  80.     case 'i':
  81.         internationalPrefix = optarg;
  82.         break;
  83.     case 'l':
  84.         longDistancePrefix = optarg;
  85.         break;
  86.     case 'v':
  87.         verbose = TRUE;
  88.         break;
  89.     case '?':
  90.         usage();
  91.         /*NOTREACHED*/
  92.     }
  93.     if (argc - optind != 1)
  94.     usage();
  95.     DialStringRules rules(argv[optind]);
  96.     rules.setVerbose(TRUE);
  97.     rules.def("AreaCode", areaCode);
  98.     rules.def("CountryCode", countryCode);
  99.     rules.def("InternationalPrefix", internationalPrefix);
  100.     rules.def("LongDistancePrefix", longDistancePrefix);
  101.     if (rules.parse()) {
  102.     char line[1024];
  103.     while (prompt() && fgets(line, sizeof (line), stdin)) {
  104.         char* cp = strchr(line, '\n');
  105.         if (cp)
  106.         *cp = '\0';
  107.         if (verbose)
  108.         printf("input = \"%s\"\n", line);
  109.         if (cp = strchr(line, '(')) {
  110.         char* ep = strchr(cp, ')');
  111.         if (ep)
  112.             *ep = '\0';
  113.         fxStr set(line, cp-line);
  114.         fxStr result = rules.applyRules(set, cp+1);
  115.         printf("%s(%s) = \"%s\"\n", (char*) set, cp+1, (char*) result);
  116.         } else {
  117.         fxStr c = rules.canonicalNumber(line);
  118.         fxStr d = rules.dialString(line);
  119.         fxStr n = rules.displayNumber(line);
  120.         printf("canonical = \"%s\"\n", (char*) c);
  121.         printf("dial-string = \"%s\"\n", (char*) d);
  122.         printf("display = \"%s\"\n", (char *) n);
  123.         }
  124.     }
  125.     }
  126.     return (0);
  127. }
  128.